class Profile < ActiveRecord::Base
  belongs_to :view_education, :class_name=>"Education",:foreign_key => "teducation_id"
  belongs_to :view_oversea, :class_name=>"Oversea",:foreign_key => "toversea_id"
  belongs_to :report_education, :class_name=>"Education",:foreign_key => "education_id"
  belongs_to :report_oversea, :class_name=>"Oversea",:foreign_key => "oversea_id"
  
  def before_create
    self.copy_view_to_report
  end
  
  def copy_view_to_report
    self.birthday=self.tbirthday
    self.sex=self.tsex
    self.education_id=self.teducation_id
    self.oversea_id=self.toversea_id
    self.experience=self.texperience
    self.updated=1
  end
  
  def copy_report_to_view
    self.tbirthday=self.birthday
    self.tsex=self.sex
    self.teducation_id=self.education_id
    self.toversea_id=self.oversea_id
    self.texperience=self.experience
    self.updated=1
  end 
  
  def self.validate_params(params)
    validation=[]
    validation<<["<li>请输入您的大名</li>"] if params[:name]==""
    validation<<["<li>你的名字好长啊</li>"] unless params[:name].length<20
    validation<<["<li>请选择性别</li>"] unless (params[:tsex].to_i==1 || params[:tsex].to_i==0)
    validation<<["<li>请选择教育背景</li>"] unless params[:teducation_id].to_i.integer? && params[:teducation_id].to_i>0 && params[:teducation_id].to_i<7
    validation<<["<li>请选海外经历</li>"] unless params[:toversea_id].to_i.integer? && params[:toversea_id].to_i>0 && params[:toversea_id].to_i<6
    validation<<["<li>请输入工作年份</li>"] if params[:texperience]==""
    return validation
  end
  
end
